from __future__ import unicode_literals

from django.utils.encoding import python_2_unicode_compatible
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.urls import reverse

# 让python2可以向python3一样处理unicode字符
@python_2_unicode_compatible
class User(AbstractUser):
    """自定义用户模型"""
    nickname = models.CharField(max_length=255,null=True,blank=True,verbose_name='昵称')
    job_title = models.CharField(max_length=50,null=True,blank=True,verbose_name='职位')
    introduction = models.TextField(null=True,blank=True,verbose_name='简介')
    picture = models.ImageField(upload_to='profile_pics/',null=True,blank=True)
    location = models.CharField(max_length=50,null=True,blank=True,verbose_name='城市')
    person_url=models.URLField(max_length=255, null=True, blank=True, verbose_name='个人链接')
    weibo = models.URLField(max_length=255,null=True,blank=True,verbose_name='微博链接')
    zhihu = models.URLField(max_length=255,null=True,blank=True,verbose_name='知乎链接')
    github = models.URLField(max_length=255,null=True,blank=True,verbose_name='github链接')
    linkedin = models.URLField(max_length=255,null=True,blank=True,verbose_name='linkedin链接')
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = '用户'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username

    def get_profile_name(self):
        if self.nickname:
            return self.nickname
        return self.username

    def get_absolute_url(self):
        return reverse("users:detail", kwargs={"username":self.username})
